﻿using System;
using Newtonsoft.Json;

namespace T.FAS.Runtime.Metadata.Entity.DataModel
{
    /// <summary>
    /// 数据查询-关联join
    /// </summary>
    [Serializable]
    public class DataQueryJoin : ICloneable
    {
        /// <summary>
        /// 主键id
        /// </summary>
        public string ID { get; set; }

        /// <summary>
        /// 数据查询id
        /// </summary>
        public string DataQueryID { get; set; }

        /// <summary>
        /// 左数据对象
        /// </summary>
        public string LeftSourceID { get; set; }

        /// <summary>
        /// 右数据对象
        /// </summary>
        public string RightSourceID { get; set; }

        /// <summary>
        /// 关联类型，0:左连接 1:内连接 2:全连接
        /// </summary>
        public int JoinType { get; set; }

        /// <summary>
        /// 关联join条件表达式
        /// </summary>
        public string JoinExpression { get; set; }

        /// <summary>
        /// 关联join条件表达式json
        /// </summary>
        public string JoinExpressionJson { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; }

        /// <summary>
        /// 备用字段
        /// </summary>
        [JsonIgnore]
        public string Ext1 { get; set; }

        /// <summary>
        /// 备用字段
        /// </summary>
        [JsonIgnore]
        public string Ext2 { get; set; }

        /// <summary>
        /// 备用字段
        /// </summary>
        [JsonIgnore]
        public string Ext3 { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        [JsonIgnore]
        public string Creator { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>        
        [JsonIgnore]
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 最后修改人
        /// </summary>
        [JsonIgnore]
        public string LastModifier { get; set; }

        /// <summary>
        /// 最后修改时间
        /// </summary>        
        [JsonIgnore]
        public DateTime LastModifyTime { get; set; }

        /// <summary>
        /// 左 数据对象实体 禁止序列化，反序列化时从DataQuerySource集合引用
        /// </summary>
        [JsonIgnore]
        public DataQuerySource LeftQuerySource { get; set; }

        /// <summary>
        /// 右 数据对象实体 禁止序列化，反序列化时从DataQuerySource集合引用
        /// </summary>
        [JsonIgnore]
        public DataQuerySource RightQuerySource { get; set; }

        public object Clone()
        {
            var join = this.MemberwiseClone() as DataQueryJoin;

            if (this.LeftQuerySource != null)
            {
                join.LeftQuerySource = this.LeftQuerySource.Clone() as DataQuerySource;
            }
            if (this.RightQuerySource != null)
            {
                join.RightQuerySource = this.RightQuerySource.Clone() as DataQuerySource;
            }

            return join;
        }
    }
}
